package logic.regulardevices;

public class Fan extends RegularDevice{

	private int[] modes = new int[3];
	private int currMode = 0;
	private boolean on = false;
	
	public Fan() {
		id="fan";
		modes[0]=0;
		modes[1]=1;
		modes[2]=2;
	}
	
	@Override
	public String receiveAndRespond(String cmd) {
		if(cmd.equals("on1") || cmd.equals("on2") || cmd.equals("on3")) {
			on=true;
			if(cmd.equals("on1")) {
				currMode=modes[0];
				return "on1";
			} else if(cmd.equals("on2")) {
				currMode=modes[1];
				return "on2";
			} else if(cmd.equals("on3")) { //checks the firealarms state.
				currMode=modes[2];
				return "on3";
			} 
		}
		
		else if(cmd.equals("check"))
			return check();
		else if(cmd.equals("off")) {
			on=false;
			return "off";
		}
			
		return invalidCommand();
	}

	@Override
	public String check() {
		if(on) {
			if(currMode == modes[0])
				return "on1";
			if(currMode == modes[1])
				return "on2";
			if(currMode == modes[2])
				return "on3";
		}
		return "off";
	}

	@Override
	public String test() {
		// TODO Auto-generated method stub
		return null;
	}

}
